package com.freecloud.javabasics.design.chain;

import com.freecloud.common.LoggerUtil;

/**
 * 责任链 抽象处理者
 * @Author: maomao
 * @Date: 2020-01-21 15:59
 */
public abstract class RequestHandler {
    /**
     * 持有后续的责任链
     */
    protected RequestHandler nextHandler;

    public RequestHandler(RequestHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    /**
     * 责任链执行方法
     * @param request
     */
    public void handleRequest(Request request){
        if(request != null){
            nextHandler.handleRequest(request);
        }
    }

    protected void pringHandling(Request request){
        LoggerUtil.println("%s handling request %s",this,request.getName());
    }
}
